import socket
import requests
from configs import data_post_url, video_post_url, data_post_url_person_num_in_a_frame_yolov5

# 函数 gethostname() 返回当前正在执行 Python 的系统主机名
res = socket.gethostbyname(socket.gethostname())


def data_post(data_dict):
    response = requests.post(data_post_url,
                             data=data_dict,
                             files=None,
                             verify=False,
                             stream=True)
    print("picture upload state: ", response.status_code)


def video_post(files):
    response = requests.post(video_post_url,
                             data={"ip": res, "type_": "video_upload"},
                             files=files,
                             verify=False,
                             stream=True)
    print("picture upload state: ", response.status_code)


def data_post_person_num_in_a_frame_yolov5(data_dict):
    response = requests.post(data_post_url_person_num_in_a_frame_yolov5,
                             data=data_dict,
                             files=None,
                             verify=False,
                             stream=True)
    print("picture upload state: ", response.status_code)


if __name__ == "__main__":
    # test_data_dict = {"ip": res, "classification": "group_of_people", "no_mask": 0, "mask": 0, "temperature": 36.0}
    # data_post(test_data_dict)
    test_files = {'file': open("./results/result.png", 'rb')}
    video_post(test_files)
